package com.atguigu.core.acc

import java.util

import org.apache.spark.util.AccumulatorV2

class MyAcc2 extends AccumulatorV2[Int, util.ArrayList[Int]] {
  private var list = new util.ArrayList[Int]()

  override def isZero: Boolean = list.size() == 0

  override def copy(): AccumulatorV2[Int, util.ArrayList[Int]] = {
    val acc = new MyAcc2
    acc.list = this.list
    acc
  }

  override def reset(): Unit = list.clear()

  override def add(v: Int): Unit = {
    list.add(v)
  }

  override def merge(other: AccumulatorV2[Int, util.ArrayList[Int]]): Unit = {

    list.addAll(other.value)
  }

  override def value: util.ArrayList[Int] = list
}
